import http from '@/config/config.js';

function request(options = {}) {
	options.url = `${http.BASE_URL}${options.url}`;
	//配置请求头
	options.header = Object.assign({
		'content-type': 'application/x-www-form-urlencoded',
		//'token': uni.getStorageSync('userinfo').token //Bearer 
	},options.header?options.header:{});
return new Promise((resolve, reject) => {
			//成功
			options.success = (res) => {
				//console.log(options,'request_options');
				if(res.statusCode === 500){
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 1000
					})
				}
				resolve(res.data)
			}
			//错误
			options.fail = (err) => {
				reject(err); //错误
				uni.showToast({
					title: '系统异常',
					icon: 'none'
				});
			};
			uni.request(options);
		})
}

export const post = (url, data = {}) => {
  return request({ url, method: 'POST', data });
};

export default request;